package com.pianke.yc.test.Activity;



import android.app.Activity;
import android.os.Bundle;
import android.widget.TextView;
import android.widget.Toast;

import com.pianke.yc.test.Classess.HttpMethod;
import com.pianke.yc.test.Classess.Job;
import com.pianke.yc.test.Net.NetObject;
import com.pianke.yc.test.R;

import org.json.JSONArray;
import org.json.JSONException;
import org.json.JSONObject;

import java.util.HashMap;
import java.util.Map;


/**
 * 兼职任务详情页
 * Created by YC on 2016/3/31.
 */
public class DetailsActivity extends Activity implements NetObject.SuccessCallback,NetObject.FailCallback{

    private String URL="http://192.168.56.1:8080/jianzhiTest/DetailsServler";
    private int id;
    private TextView title;
    private TextView place;
    private TextView time;
    private TextView money;
    private TextView jobcontent;
    private TextView jobask;
    private TextView jobcontacts;
    private TextView jobphone;


    @Override
    protected void onCreate(Bundle savedInstanceState) {
        super.onCreate(savedInstanceState);
        setContentView(R.layout.activity_details);
        id = getIntent().getIntExtra("id",-1);
        init();
        new NetObject(URL,getParmes(), HttpMethod.GET,this,this).execute();
    }

    private void init() {
       title= (TextView) findViewById(R.id.details_title);
        place= (TextView) findViewById(R.id.details_place);
        time= (TextView) findViewById(R.id.details_time);
        money= (TextView) findViewById(R.id.details_money);
        jobcontent= (TextView) findViewById(R.id.details_jobcontent);
        jobask= (TextView) findViewById(R.id.details_jobask);
        jobcontacts= (TextView) findViewById(R.id.details_jobcontacts);
        jobphone= (TextView) findViewById(R.id.details_jobphone);
    }

    private Map<String,String> getParmes(){
        Map<String,String> parmes=new HashMap<>();
        parmes.put("id",id+"");
        return parmes;
    }

    @Override
    public void onFail() {
        Toast.makeText(this, "额,加载出问题了", Toast.LENGTH_LONG).show();
    }

    @Override
    public void onSuccess(String a) {
        try {
            JSONArray json=new JSONArray(a);
            Job job=new Job((JSONObject) json.get(0));
            initdata(job);
        } catch (JSONException e) {
            e.printStackTrace();
        }
    }

    private void initdata(Job j){
        title.setText(j.title);
        place.setText(j.place);
        time.setText(j.time);
        money.setText(j.money);
        jobcontent.setText(j.jobcontent);
        jobask.setText(j.jobask);
        jobcontacts.setText(j.jobcontacts);
        jobphone.setText(j.jobphone);
    }

}
